package ynu.czs.controller;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import ynu.czs.entity.Cart;
import ynu.czs.entity.User;
import ynu.czs.feign.ServiceProviderService;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Resource
    private ServiceProviderService userFeignClient;  // 注入Feign客户端

    @GetMapping("/getUser/{userId}")
    public User getUser(@PathVariable("userId") Integer userId) {
        return userFeignClient.getUserById(userId);
    }

    @PostMapping("/createUser")
    public User createUser(@RequestBody User user) {
        return userFeignClient.createUser(user);
    }

    @PutMapping("/updateUser/{userId}")
    public User updateUser(@PathVariable("userId") Integer userId,
                           @RequestBody User user) {
        userFeignClient.updateUser(userId, user);
        return user;
    }

    @DeleteMapping("/deleteUser/{userId}")
    public String deleteUser(@PathVariable("userId") Integer userId) {
        userFeignClient.deleteUser(userId);
        return "已触发删除操作";
    }
}
